<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup aui-gutter-column-xxl">
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'common_type_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group
        formControlName="type"
        [lvGroupName]="'typeGroup'"
        [lvDisabled]="rowData"
      >
        <lv-group [lvGutter]="'24px'">
          <lv-radio [lvValue]="dataMap.saphanaDatabaseType.systemdb.value">
            {{ 'protection_system_db_label' | i18n }}
          </lv-radio>
          <lv-radio [lvValue]="dataMap.saphanaDatabaseType.tenantdb.value">
            {{ 'protection_tenant_db_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_database_instance_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select
        [lvOptions]="instanceOptions"
        formControlName="instance"
        lvValueKey="value"
        lvMode="single"
        lvShowFilter
        lvShowCheckAll
        lvFilterKey="label"
        lvFilterMode="contains"
        [lvDisabled]="rowData"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>
    <lv-form-item>
        <lv-form-label lvRequired>
            {{ 'common_name_label' | i18n }}
        </lv-form-label>
        <lv-form-control [lvErrorTip]="nameErrorTip">
            <lv-select
                    [lvOptions]="instanceDatabaseOpts"
                    formControlName="name"
                    lvValueKey="value"
                    lvShowFilter
                    lvFilterKey="label"
                    lvFilterMode="contains"
            >

            </lv-select>
        </lv-form-control>
    </lv-form-item>
  <lv-form-item
    *ngIf="formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value"
  >
    <lv-form-label lvRequired>
      {{ 'common_host_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select
        [lvOptions]="hostOptions"
        formControlName="host"
        lvValueKey="value"
        lvMode="multiple"
        lvShowFilter
        lvShowCheckAll
        lvFilterKey="label"
        lvFilterMode="contains"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item
    *ngIf="formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value"
  >
    <lv-form-label lvRequired>
      {{ 'protection_auth_mode_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-select
        formControlName="authMode"
        [lvOptions]="authOptions"
        lvValueKey="value"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item
    *ngIf="
      formGroup.value.authMode === dataMap.saphanaAuthMethod.db.value &&
      formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value
    "
  >
    <lv-form-label lvRequired>
      {{ 'common_database_user_name_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="usernameErrorTip">
      <input
        lv-input
        type="text"
        formControlName="userName"
        autocomplete="new-password"
        [placeholder]="
          i18n.get('common_database_user_name_placeholder_label')
        "
      />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item
    *ngIf="
      formGroup.value.authMode === dataMap.saphanaAuthMethod.db.value &&
      formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value
    "
  >
    <lv-form-label lvRequired>
      {{ 'protection_tenant_database_password_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="passwordErrorTip">
      <aui-inupt-with-eye
        formControlName="password"
        [placeholder]="
          i18n.get('protection_tenant_database_password_placeholder_label')
        "
      ></aui-inupt-with-eye>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item
    *ngIf="
      formGroup.value.authMode ===
        dataMap.saphanaAuthMethod.hdbuserstore.value &&
      formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value
    "
  >
    <lv-form-label lvRequired>
      {{ 'Hdbuserstore KEY' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="instanceIdErrorTip">
      <aui-inupt-with-eye
        formControlName="hdbuserstoreKey"
        [placeholder]="
          i18n.get('common_please_enter_label', [i18n.get('Hdbuserstore KEY')])
        "
      ></aui-inupt-with-eye>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item
    *ngIf="
      formGroup.value.authMode === dataMap.saphanaAuthMethod.db.value &&
      formGroup.value.type === dataMap.saphanaDatabaseType.tenantdb.value
    "
  >
    <lv-form-label lvRequired>
      {{ 'protection_system_database_port_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="portErrorTip">
      <input
        lv-input
        type="text"
        formControlName="port"
        [placeholder]="
          i18n.get('protection_system_database_port_placeholder_label')
        "
      />
    </lv-form-control>
  </lv-form-item>
</lv-form>
